package com.heima.jobs.config;

import com.heima.jobs.config.properties.XxlJobConfigProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Author XHui
 * @Since 2024/3/11 16:03
 * @Version 1.0
 */
@Log4j2
@Configuration
@EnableConfigurationProperties(XxlJobConfigProperties.class)
public class XxlJobConfig {

    @Resource
    private  XxlJobConfigProperties xxlJobConfigProperties;

    @Bean
    public XxlJobSpringExecutor xxlJobSpringExecutor(){
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(xxlJobConfigProperties.getAdminAddress());
        xxlJobSpringExecutor.setAppname(xxlJobConfigProperties.getExecutorName());
        xxlJobSpringExecutor.setPort(xxlJobConfigProperties.getExecutorPort());
        xxlJobSpringExecutor.setLogRetentionDays(30);
        xxlJobSpringExecutor.setLogPath(xxlJobConfigProperties.getLogPath());
        xxlJobSpringExecutor.setAddress(xxlJobConfigProperties.getExecutorAddress());
        return xxlJobSpringExecutor;
    }
}
